<?php

class PhotoAlbum extends DataObject {

    static $db = array(
        'Title' => 'Varchar(255)',
        'Date' => 'Date',
        'Archive' => 'Boolean',
        'RSSFeed' => 'Varchar(255)'
    );

    static $has_one = array(
        'Image' => 'Image',
        'PhotoPage' => 'PhotoPage',
    );
    static $searchable_fields = array(
        'Title',
        'Date',
    );
    
    public function getCMSFields_forPopup(){
        //$df = new DateField('Date');
        //$df->setConfig('showcalendar', true);
        //$df->setConfig('dateformat', 'dd/MM/YYYY');
        $df = new DatePickerField( 'Date' );
        //$df->setConfig('showcalendar', true);
        return new FieldSet(
            new TextField('Title'),
            $df,
            new TextField('RSSFeed'),
            new CheckboxField('Archive'),
            new ImageField('Image')
        );
    }

    public function getCMSFields(){
        //$df = new DateField('Date');
        //$df->setConfig('showcalendar', true);
        //$df->setConfig('dateformat', 'dd/MM/YYYY');
        $df = new DatePickerField( 'Date' );
        //$df->setConfig('showcalendar', true);
        return new FieldSet(
            new TextField('Title'),
            $df,
            new TextField('RSSFeed'),
            new CheckboxField('Archive'),
            new ImageField('Image')
        );
    }
    
    public function onBeforeWrite() {
        parent::onBeforeWrite();
        $PhotoPage = DataObject::get_one('PhotoPage');
        $this->PhotoPageID = $PhotoPage->ID;
    }
}